package com.zhg.demo.mybatis.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhg.demo.mybatis.entity.UserA;
import com.zhg.demo.mybatis.mapper.UserMapper;
import com.zhg.demo.mybatis.service.UserService;
import org.apache.catalina.User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserServiceimpl extends ServiceImpl<UserMapper, UserA> implements UserService {


    @Override
    public List<UserA> findAll() {
        System.out.println(1);
        //这是查询
        QueryWrapper wrapper = new QueryWrapper<UserA>();
        //selectList 查询一个集合
        List<UserA> users = this.baseMapper.selectList(wrapper);
        //add
        UserA add = new UserA();
        add.setId(3);
        add.setUsername("test");
        add.setPassword("123");
        this.baseMapper.insert(add);
        //update
        UpdateWrapper updateWrapper = new UpdateWrapper<UserA>();
        updateWrapper.eq("username", "test");//sql =
        UserA updateUser = new UserA();
        updateUser.setUsername("test2");
        this.baseMapper.update(updateUser, updateWrapper);
        // update tb_user set username='test2' where username='test'
        updateWrapper = new UpdateWrapper();
        updateWrapper.eq("username", "test2");
        this.baseMapper.delete(updateWrapper);
        //remove()  //删除
        //saveOrUpdate() // 更新或是保存
        //getOne() //获取一个
        //list() //查询集合
        //getById() 根据id 查询
        return null;
        //return userMapper.findAll();
    }

    /**
     * 更新用户信息
     * @param user 用户信息
     * @retur 不返回信息
     */
    @Transactional //spring的事务注解
    public void update(UserA user) {
        //修改用户信息

    }
}
